## Description #############################################################################
#
# Tests related to ECI to ECI transformations for orbit representations.
#
############################################################################################

# == File: ./src/orbit/orb_eci_to_eci.jl ===================================================

# -- Function: orb_eci_to_eci --------------------------------------------------------------

############################################################################################
#                                       Test Results                                       #
############################################################################################
#
# == Scenario 01 ===========================================================================
#
# Using AGI STK, it was verified that:
#
#   ╔══════════════════════╦═════════════════════════════╦═══════════════╗
#   ║   Reference Frame    ║            TEME             ║     j2000     ║
#   ╠══════════════════════╬═════════════════════════════╬═══════════════╣
#   ║ Epoch                ║ 1-Jun-2016 11:00:00.000 UTC ║ -             ║
#   ║ Mean motion          ║ 14.4 revs/day               ║ 14.4 revs/day ║
#   ║ Eccentricity         ║ 0.001111                    ║ 0.001111      ║
#   ║ Inclination          ║ 98.405˚                     ║ 98.3365˚      ║
#   ║ Argument of Perigee  ║ 90˚                         ║ 90.0604˚      ║
#   ║ RAAN                 ║ 227.336˚                    ║ 227.134˚      ║
#   ║ Mean Anomaly         ║ 320˚                        ║ 320˚          ║
#   ╚══════════════════════╩═════════════════════════════╩═══════════════╝
#
############################################################################################

@testset "Function orb_eci_to_eci" begin
    eop = fetch_iers_eop()

    # This is the Amazonia-1 orbit, which has a = 7130.982 km.
    a = 7130.982e3
    e = 0.001111
    i = 98.405 * π / 180
    Ω = 227.336 * π / 180
    ω = 90 * π / 180
    f = mean_to_true_anomaly(e, 320 * π / 180)
    epoch = date_to_jd(2016, 6, 1, 11, 0, 0)

    oe_teme  = KeplerianElements(0, a, e, i, Ω, ω, f)
    oe_j2000 = orb_eci_to_eci(oe_teme, TEME(), J2000(), epoch, eop)
    m = true_to_mean_anomaly(oe_j2000.e, oe_j2000.f)

    @test oe_j2000.a / 1000    ≈ 7130.982 atol=1e-8
    @test oe_j2000.e           ≈ e        atol=1e-8
    @test oe_j2000.i * 180 / π ≈ 98.3365  atol=1e-4
    @test oe_j2000.Ω * 180 / π ≈ 227.134  atol=1e-3
    @test oe_j2000.ω * 180 / π ≈ 90.0604  atol=1e-4
    @test m * 180/π            ≈ 320      atol=1e-8
end
